#include <ros/ros.h>
#include <sensor_msgs/Image.h>
#include <image_transport/image_transport.h>
#include <cv_bridge/cv_bridge.h>
#include <opencv2/opencv.hpp>

void depthCallback(const sensor_msgs::ImageConstPtr &msg) {
    try {
        cv::Mat img;
        img = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::TYPE_32FC1)->image;

        // 在这里对图像进行处理

        cv::imshow("Depth", img);
        cv::waitKey(1);
    }
    catch (cv_bridge::Exception &e) {
        ROS_ERROR("cv_bridge exception: %s", e.what());
    }
}

int main(int argc, char **argv) {
    ros::init(argc, argv, "cre_depth_subscriber");
    ros::NodeHandle nh;

    image_transport::ImageTransport it(nh);
    image_transport::Subscriber sub = it.subscribe("/camera/depth/image_raw", 1, depthCallback);

    cv::namedWindow("Depth");
    ros::spin();
    cv::destroyWindow("Depth");

    return 0;
}